package com.cn.wanxi.servlet;

import com.cn.wanxi.model.NewsModel;
import com.cn.wanxi.service.NewsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/findNewsById")
public class FindNewsById extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        1,拿到页面的值id
        String idstring = req.getParameter("id");
//        2.通过数据库查询，拿到数据
        NewsService newsService = new NewsService();

        NewsModel newsModel = newsService.findById(Integer.parseInt(idstring));
//        3.将拿到的数据传递给页面
        req.setAttribute("newsModel", newsModel);
//        4.跳转到页面，页面转发
        req.getRequestDispatcher("/jsp/updateNews.jsp").forward(req, resp);

    }
}
